﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZXing;
using ZXing.QrCode;

// Four Points In World Space Vector2
public class FPRIWS_V2
{
    public Vector2 U_L;
    public Vector2 U_R;
    public Vector2 D_L;
    public Vector2 D_R;

    public override string ToString()
    {
        var ul = string.Format("U_L ({0:F2},{1:F2})", U_L.x, U_L.y);
        var ur = string.Format("U_R ({0:F2},{1:F2})", U_R.x, U_R.y);
        var dl = string.Format("D_L ({0:F2},{1:F2})", D_L.x, D_L.y);
        var dr = string.Format("D_R ({0:F2},{1:F2})", D_R.x, D_R.y);
        return ul + " - " + ur + "\n"
             + dl + " - " + dr;
    }
}

public class UtilityFunctions
{
    public static FPRIWS_V2 GetCameraRectPoint_X_Y_Dimensional(Camera pCamera)
    {
        var result = new FPRIWS_V2();
        var w = pCamera.pixelWidth;
        var h = pCamera.pixelHeight;
        result.U_L = pCamera.ScreenToWorldPoint(new Vector2(0, h));
        result.U_R = pCamera.ScreenToWorldPoint(new Vector2(w, h));
        result.D_L = pCamera.ScreenToWorldPoint(new Vector2(0, 0));
        result.D_R = pCamera.ScreenToWorldPoint(new Vector2(w, 0));
        return result;
    }

    public static Color32 GetRandomColor32()
    {
        return new Color32()
        {
            r = (byte)Random.Range(0, 255),
            g = (byte)Random.Range(0, 255),
            b = (byte)Random.Range(0, 255),
            a = (byte)Random.Range(0, 255),
        };
    }

    public static Color32[] CreateCode(string pQrCodeText, int pWidth, int pHeight)
    {
        BarcodeWriter writer = new BarcodeWriter
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new QrCodeEncodingOptions
            {
                Height = pHeight,
                Width = pWidth,
            }
        };
        writer.Options.Margin = 1;
        return writer.Write(pQrCodeText);
    }


}
